/**
 * 公司简介
 */
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">报表查询</el-breadcrumb-item>
      <el-breadcrumb-item>商品库存</el-breadcrumb-item>
    </el-breadcrumb>
    <span>
      仓库：
      <el-select
        v-model="editForm.productType"
        placeholder="请选择产品类型"
        style="margin-top:20px;margin-right:30px"
      >
        <el-option
          v-for="item in brandOptions"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        ></el-option>
      </el-select>
      类别：
      <el-select v-model="editForm.productType" placeholder="请选择产品类型" style="margin-top:20px;margin-right: 30px">
        <el-option
          v-for="item in brandOptions"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        ></el-option>
      </el-select>
      商品信息:
      <el-input
        v-model="editForm.productType"
        placeholder="请输入条码、名称、规格、型号"
        style="width: 230px; margin-top: 20px; "
      ></el-input>
      <el-button type="primary" style="margin-left: 20px">查询</el-button>
      <el-button type="primary" style="margin-left: 5px">打印</el-button>
    </span>
    <!--列表-->
    <el-table
      size="small"
      :data="listData"
      highlight-current-row
      v-loading="loading"
      border
      element-loading-text="拼命加载中"
      style="width: 100%"
    >
      <el-table-column sortable align="center" prop="id" label="条码"></el-table-column>
      <el-table-column sortable align="center" prop="businessPhilosophy" label="名称"></el-table-column>
      <el-table-column sortable align="center" prop="companyProfile" label="规格"></el-table-column>
      <el-table-column sortable align="center" prop="enterpriseCulture" label="型号"></el-table-column>
      <el-table-column sortable align="center" label="颜色">
        <template slot-scope="scope">
          <img style="height: 80px" :src="scope.row.picture[0]" />
        </template>
      </el-table-column>
      <el-table-column sortable align="center" prop="createTime" label="类别"></el-table-column>
      <el-table-column sortable align="center" prop="updateTime" label="单位 "></el-table-column>
      <el-table-column sortable align="center" prop="updateTime" label="单价 "></el-table-column>
      <el-table-column sortable align="center" prop="updateTime" label="初始库存 "></el-table-column>
      <el-table-column sortable align="center" prop="updateTime" label="当前库存 "></el-table-column>
      <el-table-column sortable align="center" prop="updateTime" label="当前库存金额 "></el-table-column>
      <el-table-column align="center" label="库存流水" min-width="90">
        <template slot-scope="scope">
          <el-button size="mini" type="primary" @click="handleAdd()">添加</el-button>
          <el-button size="mini" @click="handleUpdate(scope.$index, scope.row)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 编辑界面 -->
    <el-dialog
      :title="isEdit ? '编辑' : '添加'"
      :visible.sync="editFormVisible"
      width="30%"
      @click="closeDialog"
    >
      <el-form label-width="120px" :model="editForm" ref="editForm">
        <el-form-item label="经营理念">
          <el-input
            size="small"
            v-model="editForm.businessPhilosophy"
            auto-complete="off"
            placeholder="请输入经营理念"
          ></el-input>
        </el-form-item>
        <el-form-item label="公司简介">
          <el-input
            size="small"
            v-model="editForm.companyProfile"
            auto-complete="off"
            placeholder="请输入公司简介"
          ></el-input>
        </el-form-item>
        <el-form-item label="企业文化">
          <el-input
            size="small"
            v-model="editForm.enterpriseCulture"
            auto-complete="off"
            placeholder="请输入企业文化"
          ></el-input>
        </el-form-item>
        <el-form-item label="创建时间：">
          <el-date-picker v-model="editForm.createTime" type="date" placeholder="请选择时间"></el-date-picker>
        </el-form-item>
        <el-form-item label="修改时间：">
          <el-date-picker v-model="editForm.updateTime" type="date" placeholder="请选择时间"></el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="closeDialog">取消</el-button>
        <el-button
          size="small"
          type="primary"
          :loading="loading"
          class="title"
          @click="handleDialogConfirm()"
        >保存</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  getAboutUs,
  save,
  updateCompanyProfile
} from "../../api/CompanyProfile";
const defaultEditForm = {
  id: null,
  businessPhilosophy: null,
  companyProfile: null,
  enterpriseCulture: null,
  picture: null,
  createTime: null,
  updateTime: null
};
export default {
  data() {
    return {
      loading: false, //是显示加载
      editFormVisible: false, //控制编辑页面显示与隐藏
      isEdit: false,
      editForm: Object.assign({}, defaultEditForm),
      listData: [], //数据
      list: "",
      brandOptions: []
    };
  },
  created() {
    this.getdata();
  },
  methods: {
    // 获取列表
    getdata() {
      // this.loading = true;
      getAboutUs()
        .then(res => {
          this.loading = false;
          if (res.code == 0) {
            this.$message({
              type: "info",
              message: res.message
            });
          } else {
            this.listData = res.data;
            this.listData.map(item => {
              item.picture = item.picture.split(",");
              return item.picture;
            });
          }
        })
        .catch(err => {
          this.loading = false;
          this.$message.error("菜单加载失败，请稍后再试！");
        });
    },
    // 添加
    handleAdd() {
      this.editFormVisible = true;
      this.isEdit = false;
      this.editForm = Object.assign({}, defaultEditForm);
    },
    //显示编辑界面
    handleUpdate(index, row) {
      this.editFormVisible = true;
      this.isEdit = true;
      this.editForm = Object.assign({}, row);
    },
    // 编辑、增加页面保存方法
    handleDialogConfirm() {
      this.$confirm("是否要确认?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        if (this.isEdit) {
          this.editForm.picture = this.file;
          updateCompanyProfile(this.editForm).then(res => {
            if (res.code == 1) {
              this.$message({
                message: "修改成功！",
                type: "success"
              });
            } else {
              this.$message({
                message: res.msg,
                type: "info"
              });
            }
            this.editFormVisible = false;
            this.loading = false;
            this.getdata();
          });
        } else {
          this.editForm.picture = this.file;
          save(this.editForm).then(res => {
            if (res.code == 1) {
              this.$message({
                message: "添加成功！",
                type: "success"
              });
            } else {
              this.$message({
                message: res.msg,
                type: "info"
              });
            }
            this.editFormVisible = false;
            this.loading = false;
            this.getdata();
          });
        }
      });
    },
    // 关闭编辑、增加弹出框
    closeDialog() {
      this.editFormVisible = false;
    }
  }
};
</script>
<style >
.el-input--small .el-input__inner {
  width: 70%;
}
.bth {
  float: right;
  margin-top: -30px;
  margin-left: -30px;
}
</style>
<style scoped>
.user-search {
  margin-top: 20px;
}
.userRole {
  width: 100%;
}
.el-table {
  margin-top: 50px;
}
</style>

 
 